package com.su.dolphin.utils.ui;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.su.dolphin.R;

public class DpItemView extends LinearLayout
{
    
    private ImageView mImgTitle = null;
    private ImageView mImgArrowRight = null;
    private TextView mTxtTitle = null;
    private TextView mTxtTitleSub = null;
    
    private View mView = null;
    
    public DpItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }
    
    public DpItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    
    public DpItemView(Context context) {
        this(context, null);
        init();
    }
    
    public DpItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }
    
    private void init() {
        mView = LayoutInflater.from(getContext()).inflate(R.layout.layout_dp_item, null);
        mImgTitle = (ImageView) mView.findViewById(R.id.dp_item_img_title);
        mImgArrowRight = (ImageView) mView.findViewById(R.id.dp_item_img_arrow_right);
        mTxtTitle = (TextView) mView.findViewById(R.id.dp_item_txt_title);
        mTxtTitleSub = (TextView) mView.findViewById(R.id.dp_item_txt_title_sub);
        mTxtTitle.setText("DpItemView");
        mTxtTitle.setTextColor(Color.BLACK);
        mTxtTitle.setTextSize(14);
        
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        params.gravity = Gravity.CENTER;
        this.addView(mView, params);
    }
    
    public void setItemTitleText(String text) {
        if (text != null) {
            this.mTxtTitle.setText(text);
        }
    }
    /**
     * 设置子标题
     * @param text
     * @param showTitle 是否显示上面的title 大标题
     */
    public void setItemSubText(String text, boolean showTitle) {
        if (text != null) {
            if (showTitle) {
                this.mTxtTitle.setVisibility(View.VISIBLE);
            }
            else {
                this.mTxtTitle.setVisibility(View.GONE);
                
            }
            this.mTxtTitleSub.setVisibility(View.VISIBLE);
            this.mTxtTitleSub.setText(text);
        }
    }
    
    public void setItemImage(int imgId) {
        if (imgId == -1) {
            return;
        }
        this.mImgTitle.setVisibility(View.VISIBLE);
        this.mImgTitle.setImageResource(imgId);
    }
    
    public void setItemArrowRight(int imgId) {
        this.mImgArrowRight.setImageResource(imgId);
    }
    
    public void setBackgroundImage(int resId) {
        mView.setBackgroundResource(resId);
    }
    
}
